var netcore = require('../../../utils/network.js')
var tripleDes = require('../../../utils/CKCrypto.js')

function getTeacherInfo(id,callBack){
  var map=new Map()
  map.set("teacherId",tripleDes.enCode(id))
  netcore.requestPost("teacher/getTeacherAndCourseInfo.do", map, function (success) {
    success.teacherId = tripleDes.deCode(success.teacherId)
    success.teacherHead = tripleDes.deCode(success.teacherHead)
    success.teacherName = tripleDes.deCode(success.teacherName)
    success.teacherRank = tripleDes.deCode(success.teacherRank)
    success.teacherSynopsis = tripleDes.deCode(success.teacherSynopsis)
    success.wxAccount = success.wxAccount
    success.contact = success.contact
    success.isCollection = tripleDes.deCode(success.isCollection)
    success.courseLists.forEach(function(course,index){
      course.cover = tripleDes.deCode(course.cover)
      course.id = tripleDes.deCode(course.id)
      course.price = tripleDes.deCode(course.price)
      course.title = tripleDes.deCode(course.title)
    })
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
function collectTeacher(id,callBack){
  var map = new Map()
  map.set("teacherId", tripleDes.enCode(id + ""))
  netcore.requestPost("collect/addCollectTeacher.do", map, function (success) {
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
function delCollectTeacher(id, callBack) {
  var map = new Map()
  map.set("teacherId", tripleDes.enCode(id + ""))
  netcore.requestPost("collect/delCollectTeacher.do", map, function (success) {
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
function getCollectTeacher(pageIndex,callBack){
  var map = new Map()
  map.set("currentPage", pageIndex);
  map.set("pageSize", "10");
  netcore.requestPost("collect/getCollectTeacher.do", map, function (success) {
    success.forEach(function(item,index){
      // item.userNo = tripleDes.deCode(item.userNo+"")
      item.userName = tripleDes.deCode(item.userName + "")
      item.userRealNameFirst = tripleDes.deCode(item.userRealNameFirst + "")
      item.userIcon = tripleDes.deCode(item.userIcon + "")
      item.userDes = tripleDes.deCode(item.userDes + "")
    })
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
module.exports = {
  getTeacherInfo: getTeacherInfo,
  collectTeacher: collectTeacher,
  delCollectTeacher: delCollectTeacher,
  getCollectTeacher: getCollectTeacher
}